package com.ruge.seckill.controller;

import com.ruge.core.response.Response;
import com.ruge.seckill.domain.request.SaveSeckillCouponRequest;
import com.ruge.seckill.service.SeckillCouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author ruge.wu
 * @since 2022/1/26 16:02
 */
@Slf4j
@RestController
@Api(tags = "【优惠券 秒杀 相关接口】", value = "【优惠券 秒杀 相关接口】")
@RequestMapping("seckill/coupon")
public class SeckillCouponController {


    @Resource
    private SeckillCouponService seckillCouponService;

    @PostMapping("save")
    @ApiOperation(value = "【秒杀】  新增待秒杀的优惠券")
    Response save(@RequestBody @Valid SaveSeckillCouponRequest request) {
        return seckillCouponService.save(request);
    }

    @GetMapping("list")
    @ApiOperation(value = "【秒杀】  查看所有秒杀优惠券列表")
    Response list() {
        return seckillCouponService.list();
    }

    @PostMapping("doSeckill")
    @ApiOperation(value = "【秒杀】  抢购代金券")
    Response doSeckill(@ApiParam(value = "优惠券id") @RequestParam("couponId") String couponId,
                       @ApiParam(value = "用户名") @RequestParam("aid") Long aid) {
        return seckillCouponService.doSeckill(couponId, aid);
    }

}
